#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;

class LifesGame{

    private:
        char** tablero;
        unsigned int size;

	public:
		LifesGame(int s):size(s+2){
		    tablero = new char*[size];
		    for (int i=0;i<size ;i++)
		    	tablero[i]= new char[size];
            for( int i=0; i<size; i++){
                for( int j=0; j<size; j++){
                    tablero[i][j]='.';
                }
            }

        }
        void initializer(void);
        void print(void);
        int countNeighbors(int,int);
        void iterate(void);
        void simulateLife(int);
};

void LifesGame::initializer(){
    srand(time(NULL));
    int flag;
	for( int i=1; i<size-1; i++){
		for( int j=1; j<size-1; j++){
            flag = rand()%100;
            (flag%2)? tablero[i][j]='.': tablero[i][j]='*';
		}
	}
}
void LifesGame::print(){
	for( int i=1; i<size-1; ++i){
		for( int j=1; j<size-1; ++j){
			cout<<tablero[i][j];
		}cout<<endl;
	}cout<<endl;
}
int LifesGame::countNeighbors(int i,int j){

    unsigned int c=0;
  
    return c;
}
void LifesGame::iterate(){

	//callback countNeighbors
    unsigned int c;
	for (int i=1;i<size-1 ;++i ){
		for (int j=1; j<size-1; ++j){
            c = countNeighbors(i,j);
            if( tablero[i][j]=='*'){                    // celda esta viva
                if( c!= 2 && c!=3 ) tablero[i][j]='.';
            }
            else{                                       // si celda esta muerta
                if(c==3) tablero[i][j]='*';
            }
		}
    }

}
void LifesGame::simulateLife(int count){
	for(int i=0; i<count; ++i){
		print();
		cin.get();
		iterate();
	}
}
//********************************************************************

int main(){

    LifesGame lg(10);
    lg.initializer();
    lg.simulateLife(4);

    return 0;
}
